package com.atguigu.springcloud.alibaba.controller;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.text.Collator;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;


@Service
@RefreshScope
public class myservice {

    @Value("{config.info}")
    private String configInfo;
    public String get(){
        return configInfo;
    }

    public static void main(String[] args) {
    }


    public static void sortChineseStringsByPinyin(List<String> chineseStrings) {
        // 创建拼音输出格式对象
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);

        // 使用Comparator对中文字符串进行排序
        Collections.sort(chineseStrings, Comparator.comparing(s -> {
            StringBuilder pinyinBuilder = new StringBuilder();
            for (char c : s.toCharArray()) {
                if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
                    try {
                        String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
                        if (pinyinArray != null && pinyinArray.length > 0) {
                            pinyinBuilder.append(pinyinArray[0]);
                        }
                    } catch (BadHanyuPinyinOutputFormatCombination e) {
                        e.printStackTrace();
                    }
                } else {
                    pinyinBuilder.append(c);
                }
            }
            return pinyinBuilder.toString();
        }));
        }

}
